<?php
include_once 'getTrendingNews.php';
include_once 'createTrendingWordsFile.php';

function createTrendingNewsFile(){
	
	$newsArray = getTrendingNews();
	$file = 'frontend/trendingNewsView.php';
	cleanFile($file);
			
	foreach ($newsArray as $eachNews) {
		$title = $eachNews->getTitle();
		$titleWOTags = strip_tags($title);
		$filteredTitle = removeUnwantedWords($titleWOTags);
		$link = "'buscar.php?keyword=" . $filteredTitle . "&ordenamiento=peso'>";
		$firstLine = "\n" . "<div class='newsContainer'>";
		$secondLine = "\n" . "<a class='noticias' href=" . $link . $title . "</a><br/>";
		$thirdLine = "\n" . "</div>";

		file_put_contents($file, $firstLine, FILE_APPEND | LOCK_EX);
		file_put_contents($file, $secondLine, FILE_APPEND | LOCK_EX);
		file_put_contents($file, $thirdLine, FILE_APPEND | LOCK_EX);
	}
}
?>